package com.dpwgc.alisalog.worker.aop;

import com.dpwgc.alisalog.common.util.LogUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * 切面拦截-请求响应情况获取
 */
@Aspect
@Component
public class ApiAspectj {

    /**
     * 切入点 HttpApi
     */
    @Pointcut("execution(public * com.dpwgc.alisalog.worker.input.HttpApi.*(..))")
    public void logAspect() {
    }

    /**
     * http接口错误抓取
     */
    @Around("logAspect()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {

        //处理请求
        Object result = null;

        //记录日志
        try {
            //处理请求
            result = joinPoint.proceed();
        } catch (Exception e) {
            LogUtil.error("[HTTP] Log input error", e.getMessage());
            result = -1;
        }
        return result;
    }
}
